package com.panopset.rdb;

import java.io.StringWriter;
import java.sql.ResultSet;

/**
 * VARCHAR(maxSize) data type.
 *
 * @author Karl Dinwiddie.
 *
 */
public class FieldString extends Field {

    /**
     * @param name
     *            Field name.
     * @param maxSize
     *            VARCHAR(maxSize) data type.
     */
    public FieldString(final String name, final Integer maxSize) {
        super(name);
        StringWriter sw = new StringWriter();
        sw.append("VARCHAR(");
        sw.append(maxSize.toString());
        sw.append(")");
        dataType = sw.toString();
    }

    /**
     * Data type.
     */
    private final String dataType;

    @Override
    public final String getDataType() {
        return dataType;
    }

    @Override
    public final String getQuoteIfNecessary() {
        return "'";
    }

    @Override
    public final Object getValueFromResultSet(final ResultSet rs)
            throws Exception {
        return rs.getString(getName());
    }
}
